Imports System
Imports System.Drawing
Imports System.Collections
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports C1.Win.C1FlexGrid
Public Class HostedControl
    Private _flex As C1FlexGrid
    Private _ctl As Control
    Private _Row As Row
    Private _col As Column

    Public Sub New(ByVal flex As C1FlexGrid, ByVal hosted As Control, ByVal row As Integer, ByVal col As Integer)

        ' save info
        _flex = flex
        _ctl = hosted
        _Row = flex.Rows(row)
        _col = flex.Cols(col)

        ' insert hosted control into grid
        _flex.Controls.Add(_ctl)
    End Sub

    Public Function UpdatePosition() As Boolean

        ' get row/col indices
        Dim r As Integer = _Row.Index
        Dim c As Integer = _col.Index
        If r < 0 Or c < 0 Then
            Return False
        End If
        ' get cell rect
        Dim rc As Rectangle = _flex.GetCellRect(r, c, False)

        ' hide control if out of range
        If rc.Width <= 0 Or rc.Height <= 0 Or Not rc.IntersectsWith(_flex.ClientRectangle) Then
            _ctl.Visible = False
            Return True
        End If
        ' move the control and show it
        _ctl.Bounds = rc
        _ctl.Visible = True

        ' done
        Return True
    End Function
End Class
